
/**
 * @Title: App.java
 * @Package com.jiuyang.baoxian
 * @Description: TODO(用一句话描述该文件做什么)
 * @author ChangJianlong
 * @date 2014-12-4 上午11:48:45
 * @version V1.0
 */
package com.bxd.baodan;

import android.support.multidex.MultiDexApplication;

import com.bxd.baodan.app.LoginInfo;
import com.bxd.baodan.util.AppManager;
import com.bxd.baodan.util.DialogUtil;
import com.bxd.baodan.util.SpUtil;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.tencent.TIMGroupReceiveMessageOpt;
import com.tencent.TIMLogLevel;
import com.tencent.TIMManager;
import com.tencent.TIMOfflinePushListener;
import com.tencent.TIMOfflinePushNotification;
import com.tencent.qalsdk.sdk.MsfSdkUtils;
import com.tencent.qcloud.timchat.utils.Foreground;
import com.umeng.socialize.Config;
import com.umeng.socialize.PlatformConfig;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.common.QueuedWork;

/**
 *
 */
public class App extends MultiDexApplication {
    /**
     * 全局唯一实例
     */
    public static App instance;

    public static App getContext() {
        return instance;
    }

   public static int chat_msg ,answer_msg ,sys_msg,msg_count;


    {
        // TODO:三方登录替换各个平台的Key
        PlatformConfig.setWeixin("wx6b7434e8159f51d8", "7ca579573922221b084335b1249ff2e2");
        PlatformConfig.setQQZone("1101721722", "z8XaRu5iKqpx1IJv");
        PlatformConfig.setSinaWeibo("3953881312", "9ebe016fb6effed732f4f66716a36f6b", "http://www.bxd365.com/app/");
    }

    @Override
    public void onCreate() {
        super.onCreate();


        Config.DEBUG = true;
        QueuedWork.isUseThreadPool = false;
        UMShareAPI.get(this);

        instance = this;
//		isFirst();
        //初始化imageLoader环境
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
                getApplicationContext()).build();
        ImageLoader.getInstance().init(config);
        TIMManager.getInstance().setLogLevel(TIMLogLevel.OFF);
        initIM();
    }

    private void initIM() {
        Foreground.init(this);

        if (MsfSdkUtils.isMainProcess(this)) {
            TIMManager.getInstance().setOfflinePushListener(new TIMOfflinePushListener() {
                @Override
                public void handleNotification(TIMOfflinePushNotification notification) {
                    if (notification.getGroupReceiveMsgOpt() == TIMGroupReceiveMessageOpt.ReceiveAndNotify) {
                        //消息被设置为需要提醒
                        notification.doNotify(getApplicationContext(), R.drawable.logo_icon);
                    }
                }
            });
        }

    }

    public void initDefaultValues() {
        if (LoginInfo.getInstance(this).isFirst()) {
            SpUtil.getInstance().savaBoolean("receive_dingyue_push", true);//订阅消息
            SpUtil.getInstance().savaBoolean("receive_new_notifacation", true);//新消息提醒
        }
    }

    /**
     * 关闭Activity列表中的所有Activity
     */
    public void exit() {

        AppManager.getInstance().exitApp();

    }

    public void showToast(String string) {
        DialogUtil.getInstance().showToast(App.getContext(), string);
    }
}
